using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;

namespace OpenFlashChartLib
{
    public class PieGraphType : RenderBase, IValueSetRenderer
    {
        public static readonly string PieGraphToken = "pie";
        public static readonly string PieLabelsToken = "pie_labels";
        private int _valueSet = 0;
        private int _alpha = 60;
        private string _lineColor = "#505050";
        private string _labelColor = "#000000";

        /// <summary>
        /// The number of the set of values. It neede to wirte lile bar_2, bar_3 for graph type and values
        /// value_2, value_3
        /// </summary>
        public int ValueSet
        {
            get { return _valueSet; }
            set { _valueSet = value; }
        }

        public string GraphTypeTocken
        {
            get { return PieGraphToken; }
        }

        /// <summary>
        /// Pie part transparency. 100 - no transparency, 0 - full transparency
        /// </summary>
        public int Alpha
        {
            get { return _alpha; }
            set { _alpha = value; }
        }

        /// <summary>
        /// 6 hexadecimal digits of line color with first # sign
        /// </summary>
        public string LineColor
        {
            get { return _lineColor; }
            set { _lineColor = value; }
        }

        /// <summary>
        /// 6 hexadecimal digits of labels color with first # sign
        /// </summary>
        public string LabelColor
        {
            get { return _labelColor; }
            set { _labelColor = value; }
        }


        public List<string> Colors
        {
            get { return _colors; }
            set { _colors = value; }
        }

        private int _fontSize = 12;
        /// <summary>
        /// Label font size in pixels
        /// </summary>
        public int FontSize
        {
            get { return _fontSize; }
            set { _fontSize = value; }
        }

        private List<string> _colors;

        public override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
            if (_colors != null)
            {
                KeyValueList cList = new KeyValueList("colours");
                foreach (string color in _colors)
                {
                    if (color.StartsWith("#"))
                    {
                        cList.Values.Add(color);
                    }
                    else
                    {
                        cList.Values.Add("#" + color);
                    }
                }
                if (cList.Values.Count > 0)
                    cList.Render(writer);
            }
        }

        public override void RenderContent(HtmlTextWriter writer)
        {
            string token = PieGraphToken;
            if (ValueSet > 0)
                token += "_" + ValueSet;
            writer.Write(token);
            writer.Write("=");
            writer.Write(Alpha);
            if (!string.IsNullOrEmpty(LineColor))
            {
                writer.Write(",");
                writer.Write(LineColor);
            }
            writer.Write(",{font-size:");
            writer.Write(_fontSize);
            writer.Write("px");
            if (!string.IsNullOrEmpty(LabelColor))
            {
                writer.Write(";");
                writer.Write(LabelColor);
            }
            writer.Write("}");
        }
    }
}
